package ru.stepuk.modern.distributions;

import ru.stepuk.modern.generators.RandomNumberGenerator;

/**
 *
 * @author ivan
 */
public class ErlangDistribution implements Distribution {

    private int shape;
    private double rate;
    private RandomNumberGenerator g;
    private ExponentialDistribution ed;

    public ErlangDistribution(RandomNumberGenerator g, int shape, double rate) {
        this.shape = shape;
        this.rate = rate;
        this.g = g;
        ed = new ExponentialDistribution(g, shape / rate);
    }

    public double getRate() {
        return rate;
    }

    public int getShape() {
        return shape;
    }

 

    public double nextValue() {
        double result = 0;
        for (int i = 0; i < shape; i++) {
            result += ed.nextValue();
        }
        return result;
    }

    @Override
    public String toString() {
        return "erlang";
    }
}
